package com.wb.controller;

import com.wb.entity.JpaTestBean;
import com.wb.service.IJpaTestService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName : JpaTestController
 * @Author : 神经刀
 * @Date : 2019/6/12 : 9:47
 * @Version : 1.0
 */
@RestController(value = "jpaTestController")
@RequestMapping(value = "/")
public class JpaTestController {

    private final Logger logger = LoggerFactory.getLogger(JpaTestController.class);

    @Resource(name = "jpaTestServer")
    private IJpaTestService iJpaTestService;

    @RequestMapping(value = "jpa_findAll")
    public List<JpaTestBean> findAll() {
        return iJpaTestService.findAll();
    }

    @RequestMapping(value = "findByName", method = RequestMethod.POST)
    @ResponseBody
    public List<JpaTestBean> findByName(JpaTestBean jpaTestBean) {
        logger.info("jpaTestBean: {}", jpaTestBean);
        List<JpaTestBean> result = new ArrayList<>(2);
        result.add(new JpaTestBean(1, "one", 1));
        result.add(new JpaTestBean(2, "two", 2));
        return result;
    }

    @RequestMapping(value = "getJpaTestList", method = RequestMethod.GET)
    @ResponseBody
    public List<JpaTestBean> getJpaTestList(JpaTestBean jpaTestBean) {
        logger.info("jpaTestBean: {}", jpaTestBean);
        List<JpaTestBean> result = new ArrayList<>(2);
        result.add(new JpaTestBean(1, "one", 1));
        result.add(new JpaTestBean(2, "two", 2));
        return result;
    }
}
